﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_Click(object sender, EventArgs e)
        {
            string sql = "select * from StudentInfo" +
                " where stu_name = @name";

            SqlParameter[] p =
            {
                new SqlParameter("@name",TbxUserName.Text),
            };
            SqlDataReader sdr = SqlHelper.ExcuteReader(sql, p);
            if (sdr.Read())
            {
                LabelInfo.Text = "用户名已存在";
            }
            else
            {
                string sql2 = "insert into StudentInfo(stu_name,gender,email) " +
                "values(@name, @gender, @email)";
                SqlParameter[] p2 =
                {
                    new SqlParameter("@name",TbxUserName.Text),
                    new SqlParameter("@gender",RBtn_male.Checked ? 1:0),
                    new SqlParameter("email",TbxEmail.Text)
                };

                if (SqlHelper.ExecuteNonQuery(sql2, p2) == 1)
                {
                    LabelInfo.Text = "注册成功，<a href='Login.aspx'>去登陆</a>";
                }
                else
                {
                    LabelInfo.Text = "注册失败";
                }
            }


        }
    }
}